package com.ssm.springboot.controller;

import com.ssm.springboot.pojo.Course;
import com.ssm.springboot.pojo.DataInfo;
import com.ssm.springboot.service.QfCourseService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (QfCourse)表控制层
 *
 * @author makejava
 * @since 2021-12-23 15:06:01
 */
@RestController
@RequestMapping("/course")
public class QfCourseController {
    /**
     * 服务对象
     */
    @Resource
    private QfCourseService qfCourseService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequiresPermissions(value = {"/course/selectOne"})
    @RequestMapping("/selectOne")
    public DataInfo selectOne(@RequestParam("id")Integer id) {
        return qfCourseService.queryById(id);
    }

    /**
     * 查询全部课程
     * @param page 当前页数
     * @param limit 每页显示条数
     * @return 返回参数
     */
    @RequiresPermissions(value = {"/course/selectAll"})
    @RequestMapping("/selectAll")
    public DataInfo selectAll(@RequestParam("page")int page,@RequestParam("limit")int limit) {
        return qfCourseService.queryAllByLimit(page,limit);
    }

    /**
     * 删除课程
     * @param id 课程id
     * @return 返回参数
     */
    @RequiresPermissions(value = {"/course/delete"})
    @RequestMapping(value = "/delete",method =RequestMethod.POST )
    public DataInfo delete(int id){
        return qfCourseService.deleteById(id);
    }

    //增加课程
    @RequestMapping("/add")
    @RequiresPermissions(value = {"/course/add"})
    public DataInfo add(@RequestBody Course course){
        DataInfo insert = qfCourseService.insert(course);
        return insert;
    }

    //更新课程
    @RequestMapping("/update")
    @RequiresPermissions(value = {"/course/update"})
    public DataInfo update(@RequestBody Course course){
        return qfCourseService.update(course);
    }

    //通过课程类型,查新课程列表
    @RequiresPermissions(value = {"/course/selectByClassify"})
    @RequestMapping("/selectByClassify")
    public DataInfo selectByClassify(@RequestParam("id")int id,@RequestParam("page")int page,@RequestParam("limit")int limit){

        return qfCourseService.selectByClassify(id,page,limit);
    }

    //通过教师id,查新课程列表
    @RequiresPermissions(value = {"/course/selectByTeach"})
    @RequestMapping("/selectByTeach")
    public DataInfo selectByTeach(@RequestParam("id")int id,@RequestParam("page")int page,@RequestParam("limit")int limit){

        return qfCourseService.selectByTeach(id,page,limit);
    }

}